﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using Flixr.Data;
using Flixr.Data.Model;
using Flixr.Models;

namespace Flixr.Controllers
{
    public class HomeController : Controller
    {
        private FlixrDbContext db = new FlixrDbContext();
        public ActionResult Index()
        {
            IndexVM iVm = new IndexVM();
            iVm.Message = "Your movies";
            return View(iVm);
        }
        public ActionResult Detail(int id)
        {
            DetailVM dVm = new DetailVM();
            dVm.Message = "Move Details";
            using (FlixrDbContext db = new FlixrDbContext())
            {
                var mResults = db.Movies.FirstOrDefault(m => m.MovieId == id);
                byte[] image = mResults.MoviePoster;
                string imageData = Convert.ToBase64String(image);
                string imageDataUrl = string.Format("data:image/jpg;base64, {0}", imageData);
                ViewBag.ImageData = imageDataUrl;
                dVm.Movie = (Movie)mResults;
                var results = db.Actors.Where(a => a.MovieId == id).ToList();
                dVm.MyActors = results;
            }
            return View(dVm);
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}